<!--
 * @Author: sky 11864026+jfcode81@user.noreply.gitee.com
 * @Date: 2025-10-21 16:52:26
 * @LastEditors: sky 11864026+jfcode81@user.noreply.gitee.com
 * @LastEditTime: 2025-10-21 18:13:20
 * @FilePath: \trading-center-pc\components\marketList.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="bazaar-section wrapper_1200">
    <div class="market-bazaar">
      <div class="section-header">
        <h3>
          <font-awesome-icon :icon="['fas', 'store-alt']" class="title-icon" />
          昌欣集市
        </h3>
        <NuxtLink to="/market/home" class="more-link">
          <span>查看全部</span>
          <font-awesome-icon :icon="['fas', 'angle-double-right']" class="arrow-icon" />
        </NuxtLink>
      </div>
      <div class="bazaar-content">
        <div class="bazaar-intro">
          <div class="intro-main">
            <h4>帮助农民销售自产农货</h4>
            <p class="intro-desc">
              昌欣集市是专为农户打造的交易平台，通过移动+PC端，简化农户卖货流程，增加农户宣传，帮助农户提前预告上市，直接通过交易码完成交易。
            </p>
          </div>
          <div class="intro-features">
            <div class="feature-item">
              <div class="feature-icon">
                <font-awesome-icon :icon="['fas', 'mobile-alt']" class="icon" />
              </div>
              <div class="feature-content">
                <h5>移动+PC端</h5>
                <p>支持多端访问，随时随地交易</p>
              </div>
            </div>
            <div class="feature-item">
              <div class="feature-icon">
                <font-awesome-icon :icon="['fas', 'qrcode']" class="icon" />
              </div>
              <div class="feature-content">
                <h5>扫码交易</h5>
                <p>通过扫描交易码，快速完成交易</p>
              </div>
            </div>
            <div class="feature-item">
              <div class="feature-icon">
                <font-awesome-icon :icon="['fas', 'calendar-check']" class="icon" />
              </div>
              <div class="feature-content">
                <h5>提前预告</h5>
                <p>农户可提前发布上市信息，对接采购需求</p>
              </div>
            </div>
            <div class="feature-item">
              <div class="feature-icon">
                <font-awesome-icon :icon="['fas', 'handshake']" class="icon" />
              </div>
              <div class="feature-content">
                <h5>简化流程</h5>
                <p>降低使用门槛，让农户轻松上手</p>
              </div>
            </div>
          </div>
        </div>
        <div class="bazaar-showcase">
          <div class="farmer-cards">
            <div v-for="item in marketList.list" :key="item.id" class="farmer-card">
              <div class="card-header">
                <div class="avatar-wrapper">
                  <el-image :src="item.sellerAvatar" alt="" class="w-32px h-32px b-rd-50%" />
                </div>
                <div class="farmer-name">{{ item.sellerNickname }}</div>
                <div class="product-type">
                  <el-tag class="type-tag">{{ item.mushroomName }}</el-tag>
                </div>
              </div>
              <div class="card-body">
                <div v-if="false" class="preview-section">
                  <div class="preview-date">预计上市{{ dateFormat(item.createTime) }}</div>
                </div>
                <div v-if="item.price" class="price-section">
                  <div class="price-main">
                    <span class="currency">¥</span>
                    <span class="amount">{{ item.price }}</span>
                  </div>
                  <div class="price-sub">/斤</div>
                </div>
                <div class="stock-section">
                  <span class="stock-label">库存数量</span>
                  <span class="stock-value">{{ item.quantityAvailable }}/斤</span>
                </div>
              </div>
              <div class="card-footer">
                <div class="location-info">
                  <font-awesome-icon :icon="['fas', 'map-marker-alt']" class="icon" />
                  <span>中国 北京</span>
                </div>
                <div class="code-info">
                  <span>123123</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, ref, watch, computed } from 'vue'
import { marketListApi } from '@/server/marketApi'
import { MarketListQuery } from '~/types/market'
import { dateFormat } from '~/utils/filter'

const marketList = reactive({
  list: [],
  total: 0,
})
const where = reactive<MarketListQuery>({
  page: 1,
  limit: 10,
})
const listLoading = ref<boolean>(false)

const getMarketList = async () => {
  listLoading.value = true
  try {
    let data = await marketListApi(where)
    marketList.list = data.list
    marketList.total = data.total
    listLoading.value = false
  } catch (err) {
    listLoading.value = false
  }
}
getMarketList()
</script>
<style scoped lang="scss">
.wrapper_1200 {
  width: 1400px;
  padding: 0 20px;
}
.bazaar-showcase {
  flex: 1.5;
}
.market-bazaar {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px #0000001a;
  margin-bottom: 16px;
  padding: 20px;
  .section-header {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    h3 {
      align-items: center;
      color: #333;
      display: flex;
      font-size: 20px;
      font-weight: 600;
      gap: 8px;
      margin: 0;
    }
    .title-icon {
      color: #e4393c;
      font-size: 22px;
    }
    .more-link {
      align-items: center;
      color: #666;
      display: flex;
      font-size: 14px;
      gap: 6px;
      text-decoration: none;
      transition: all 0.3s;
    }
  }
  .bazaar-content {
    align-items: stretch;
    animation: fadeInUp 0.8s ease-out;
    display: flex;
    gap: 20px;
    .bazaar-intro {
      background: linear-gradient(135deg, #f8f9fa, #e9ecef);
      border-radius: 8px;
      display: flex;
      flex: 0.5;
      flex-direction: column;
      padding: 15px;
      .intro-main {
        margin-bottom: 12px;
        h4 {
          color: #333;
          font-size: 18px;
          font-weight: 600;
          line-height: 1.4;
          margin: 0 0 8px;
        }
        .intro-desc {
          color: #666;
          font-size: 14px;
          line-height: 1.5;
          margin: 0;
        }
      }
      .intro-features .feature-item {
        align-items: flex-start;
        display: flex;
        gap: 8px;
        margin-bottom: 10px;
        .feature-icon {
          align-items: center;
          background: #e4393c;
          border-radius: 50%;
          display: flex;
          flex-shrink: 0;
          height: 28px;
          justify-content: center;
          width: 28px;
          .icon {
            color: #fff;
            font-size: 12px;
          }
        }
        .feature-content {
          flex: 1;
          h5 {
            color: #333;
            font-size: 14px;
            font-weight: 600;
            line-height: 1.3;
            margin: 0 0 3px;
          }
          p {
            color: #666;
            font-size: 12px;
            line-height: 1.4;
            margin: 0;
          }
        }
      }
    }
  }
}
.farmer-cards {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, 1fr);
  .farmer-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    transition: all 0.3s;
    &:hover {
      border-color: #e4393c;
      box-shadow: 0 4px 12px #0000001a;
      transform: translateY(-2px);
    }
    .card-header {
      align-items: center;
      background: #fafafa;
      border-bottom: 1px solid #f0f0f0;
      display: flex;
      gap: 6px;
      padding: 8px;
      .card-wrapper {
        border-radius: 50%;
        flex-shrink: 0;
        height: 32px;
        overflow: hidden;
        width: 32px;
      }
      .farmer-name {
        color: #333;
        flex: 1;
        font-size: 11px;
        font-weight: 600;
      }
      .product-type {
        display: flex;
        gap: 3px;
        margin-left: auto;
        .type-tag {
          background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
          border-radius: 8px;
          box-shadow: 0 1px 3px #ee5a6f4d;
          color: #fff;
          font-size: 9px;
          font-weight: 600;
          padding: 2px 6px;
        }
      }
    }
    .card-body {
      display: flex;
      flex-direction: column;
      flex-grow: 1;
      justify-content: center;
      padding: 10px 8px;
      .preview-section {
        align-items: center;
        background: linear-gradient(135deg, #f8fff8, #e8f5e8);
        border: 1px solid #e0f0e0;
        border-radius: 8px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin-bottom: 8px;
        padding: 8px;
        .preview-date {
          background: #fff;
          border: 1px solid #4caf50;
          border-radius: 6px;
          box-shadow: 0 2px 4px #2e7d3233;
          color: #2e7d32;
          font-size: 12px;
          font-weight: 600;
          padding: 6px 10px;
          text-align: center;
        }
      }
      .price-section {
        align-items: baseline;
        display: flex;
        justify-content: center;
        margin-bottom: 6px;
        .price-main {
          align-items: baseline;
          display: flex;
          .currency {
            color: #e4393c;
            font-size: 14px;
            font-weight: 600;
          }
          .amount {
            color: #e4393c;
            font-size: 22px;
            font-weight: 700;
            line-height: 1;
          }
        }
        .price-sub {
          color: #999;
          font-size: 10px;
          margin-left: 2px;
        }
      }
      .stock-section {
        color: #666;
        font-size: 10px;
        text-align: center;
        .stock-label {
          color: #999;
          margin-right: 4px;
        }
        .stock-value {
          color: #666;
          font-weight: 600;
        }
      }
    }
    .card-footer {
      align-items: center;
      background: #fafafa;
      border-top: 1px solid #f0f0f0;
      color: #666;
      display: flex;
      font-size: 9px;
      justify-content: space-between;
      padding: 6px 8px;
      .location-info {
        align-items: center;
        display: flex;
        gap: 3px;
        .icon {
          color: #999;
          font-size: 9px;
        }
        span {
          color: #666;
          font-size: 9px;
        }
      }
      .code-info {
        span {
          color: #999;
          font-family: monospace;
          font-size: 9px;
          font-weight: 600;
        }
      }
    }
  }
}
</style>
